package tetris;

import java.awt.*;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.*;

public class Game extends JFrame {
    
	private static final long serialVersionUID = 1L;

    Image dbImage;
    Graphics dbg;
    

    // Menu Buttons
    Rectangle startButton = new Rectangle(90, 150, 125, 35);
    Rectangle hscoresButton = new Rectangle(90, 210, 125, 35);
    Rectangle quitButton = new Rectangle(90, 270, 125, 35);
       
    // Constructor
    public Game(){
        this.setTitle("Tetris");
        this.setSize(300,600);
        this.setResizable(false);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setVisible(true);
        this.setBackground(Color.DARK_GRAY);
        this.addKeyListener(new KeyHandler());
        this.addMouseListener(new MouseHandler());
        this.addMouseMotionListener(new MouseHandler());
    }
    
    JLabel statusbar;
    
    public void startGame() {
        Table table = new Table(this);
        add(table);
    	setLocationRelativeTo(null);
        setVisible(true);
    }
    
    public void viewHscores() {
    	System.out.println("HIGHSCORES TABLE");
    }
    
    public void quitGame() {
    	System.exit(0);
    }
    
    public static void main(String[] args){
        Game game = new Game();
        game.setLocationRelativeTo(null);
        game.setVisible(true);
    }
    
    @Override
    public void paint(Graphics g){
        dbImage = createImage(getWidth(), getHeight());
        dbg = dbImage.getGraphics();
        draw(dbg);
        g.drawImage(dbImage, 0, 0, this);
    }
    public void draw(Graphics g){
        
        g.setFont(new Font("Arial", Font.BOLD, 26));
        g.setColor(Color.WHITE);
        g.drawString("TETRIS GAME", 60, 75);
        g.setColor(Color.ORANGE);
        g.setFont(new Font("Arial", Font.BOLD, 14));
        g.fillRect(startButton.x, startButton.y, startButton.width, startButton.height);
        g.setColor(Color.BLACK);
        g.drawString("Start Game", startButton.x+26, startButton.y+21);
        g.setColor(Color.ORANGE);
        g.fillRect(hscoresButton.x, hscoresButton.y, hscoresButton.width, hscoresButton.height);
        g.setColor(Color.BLACK);
        g.drawString("High Scores", hscoresButton.x+20, hscoresButton.y+21);
        g.setColor(Color.ORANGE);
        g.fillRect(quitButton.x, quitButton.y, quitButton.width, quitButton.height);
        g.setColor(Color.BLACK);
        g.drawString("Quit Game", quitButton.x+28, quitButton.y+21);
        
        
    }
   
    public class KeyHandler extends KeyAdapter {
        @Override
        public void keyPressed(KeyEvent e){

        }
        @Override
        public void keyReleased(KeyEvent e){

        }
    }
    public class MouseHandler extends MouseAdapter {
        @Override
        public void mouseMoved(MouseEvent e){
            
        }
        @Override
        public void mousePressed(MouseEvent e){
            int mx = e.getX();
            int my = e.getY();
            if(mx > startButton.x && mx < startButton.x+startButton.width && my > startButton.y && my < startButton.y+startButton.height)
            	startGame();
            if(mx > hscoresButton.x && mx < hscoresButton.x+hscoresButton.width && my > hscoresButton.y && my < hscoresButton.y+hscoresButton.height)
            	viewHscores();
            if(mx > quitButton.x && mx < quitButton.x+quitButton.width && my > quitButton.y && my < quitButton.y+quitButton.height)
            	quitGame();
        }
    }
    
}